﻿using CommonLib;
using CommonLib.Pattern.Pool;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ReusableRoleBase : ReusableObject
{
	public RoleCtrl Role;//{ get; protected set; }
	protected string ObjectPath { get; set; } 

	public ReusableRoleBase()
	{
		ObjectPath = "ReusableObject/Player";
	}

	public void ResetParent(Transform ts)
	{
		Role.transform.SetParent(ts);
		Role.transform.position = Vector3.zero;
		Role.transform.localScale = Vector3.one;
	}

	protected override GameObject CreateSelf()
	{
		GameObject go = GameResourceLoader.Instance.LoadFromResource<GameObject>(ObjectPath);
		IsCreated = true;
		Role = Instantiate(go).GetComponent<RoleCtrl>();
		Role.RA_OnDie += (role) =>
		{
			this.UnUse();
		};
		return Role.gameObject;
	}
	public override void Resume()
	{
		base.Resume();
		Child.SetActive(true);
	}
	public override void Recycle()
	{
		base.Recycle();
		Child.SetActive(false);
	}

#if UNITY_EDITOR
	[ContextMenu("Recycle")]
	public void RadomCreate()
	{
		this.UnUse();
	}
#endif
}
